using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace smartBrowser.GUI
{
    public partial class LoadingPanel : Form
    {
        private int max_value;

        private delegate void callBackDelegate();

        public LoadingPanel(int max_value)
        {
            this.max_value = max_value;
            InitializeComponent();
            this.progressBar1.Maximum = max_value;
        }
        
        public void NextStep() {
            this.newStep();
        }
        
        private void newStep()
        {
            if (this.progressBar1.InvokeRequired)
            {
                callBackDelegate d = new callBackDelegate(newStep);
                this.Invoke(d);
            }
            else
            {
                if (this.progressBar1.Value == this.progressBar1.Maximum) {
                    this.Dispose();
                }
                
                this.progressBar1.PerformStep();
            }
        }
        public void updateMaxValue(int increment) {
            this.progressBar1.Maximum += increment;
        }
    }
}